<?php

namespace App\Providers;

use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        //
        Validator::extend('is_phone', function($attribute, $value, $parameters, $validator) {

            return preg_match('/^1[345789]{1}\d{9}$/', $value);
        });

        Validator::extend('not_before', function ($attribute, $value, $parameters, $validator) {
            $data = $validator->attributes();

            if (isset($data[$parameters[0]]) && !empty($value)) {
                return intval($data[$parameters[0]]) <= intval($value);
            }

            return true;
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
